package com.lesso.yjy.sunflower.executor.handler;

import com.lesso.yjy.sunflower.pojo.vo.EmployeeVO;
import com.lesso.yjy.sunflower.service.IEmployeeService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;

@Component
@Slf4j
public class SunflowerJob {
    @DubboReference
    private IEmployeeService employeeService;

    @XxlJob("sunflower-job")
    public void execute(String s) {
        log.info("定时任务时间，当前时间：{}，请求参数：{}", LocalDateTime.now(), XxlJobHelper.getJobParam());
        XxlJobHelper.log("传入参数：{} {}", s, XxlJobHelper.getJobParam());
        XxlJobHelper.log("hello xxl job");
        log.info("hello");
    }

    @XxlJob("getEmployee")
    public void getEmployee() {
        String param = XxlJobHelper.getJobParam();
        if (StringUtils.hasText(param)) {
            EmployeeVO vo = employeeService.getBy(Long.parseLong(param));
            log.info("员工id: {}，员工详细信息: {}", param, vo);
            return;
        }
        log.error("传入参数不能为空");
    }
}
